<div [@routerTransition]>
    <div class="content d-flex flex-column flex-column-fluid">

        <sub-header [title]="'PromotionManage' | localize" [description]="'PromotionManage' | localize">
            <div role="actions">
                <button class="btn btn-primary" (click)="createPromotion()">
                    <i class="fa fa-plus"></i>
                    {{l("Create")}}{{l("PromotionActivity")}}</button>
            </div>
        </sub-header>

        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">

                    <div class="row">
                        <form class="horizontal-form" autocomplete="off">
                            <div>
                                <div class="row align-items-center mb-4">
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('name')}}</label>
                                            <div class="input-group">
                                                <input [(ngModel)]="filterText" name="filterText"
                                                    class="form-control m-input" (keyup.enter)="getSchedule()"
                                                    [placeholder]="l('SearchWithThreeDot')" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>{{l('type')}}</label>
                                            <div class="input-group">
                                                <select class="form-control" [(ngModel)]="PromotionType"
                                                    name="PromotionType">
                                                    <option value="">{{l('All')}}</option>
                                                    <option value="0">{{l('InShop')}}</option>
                                                    <!-- <option value="1">{{l('InGroup')}}</option> -->
                                                    <option value="2">{{l('InProduct')}}</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-2">
                                        <div class="form-group m-form__group align-items-center">
                                            <label>&nbsp;</label>
                                            <div class="input-group">
                                                <button type="button" class="btn btn-primary"
                                                    [buttonBusy]="primengTableHelper.isLoading" (click)="getSchedule()">
                                                    <i class="la la-refresh"></i>
                                                    {{l("search")}}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="row align-items-center">
                        <div class="primeng-datatable-container" [busyIf]="primengTableHelper.isLoading">
                            <p-table #dataTable (onLazyLoad)="getSchedule($event)" [value]="primengTableHelper.records"
                                [rows]="primengTableHelper.defaultRecordsCountPerPage"
                                [(selection)]="schedulePublishList" [paginator]="false" [lazy]="true"
                                [resizableColumns]="primengTableHelper.resizableColumns"
                                [responsive]="primengTableHelper.isResponsive">
                                <ng-template pTemplate="header">
                                    <tr>
                                        <th>{{l('Actions')}}</th>
                                        <!-- <th style="width: 5.0em">
                                            <p-tableHeaderCheckbox></p-tableHeaderCheckbox>
                                        </th> -->
                                        <th style="width:5%">{{l('RecordId')}}</th>
                                        <th>{{l('name')}}</th>
                                        <th>{{l('outerId')}}</th>
                                        <th pSortableColumn="startTime">
                                            {{l('startDate')}}
                                            <p-sortIcon field="startTime"></p-sortIcon>
                                        </th>
                                        <th pSortableColumn="endTime">{{l('endDate')}}
                                            <p-sortIcon field="endTime"></p-sortIcon>
                                        </th>
                                        <th>{{l('type')}}</th>
                                        <th>{{l('discountType')}}</th>
                                        <th>{{l('value')}}</th>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="body" let-record let-i="rowIndex">
                                    <tr [pSelectableRow]="record" [attr.trid]="record.id">
                                        <td>
                                            <div class="btn-group dropdown" dropdown normalizePosition>
                                                <button class="dropdown-toggle btn btn-sm btn-primary"
                                                    data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                    aria-expanded="false">
                                                    <i class="fa fa-cog"></i>
                                                    <span class="caret"></span> {{l("Actions")}}
                                                </button>
                                                <ul class="dropdown-menu" *dropdownMenu>
                                                    <li>
                                                        <a (click)="edit(record)" class="icon-bianji dropdown-item">{{l('Edit')}}</a>
                                                    </li>
                                                    <li *ngIf="record.promotionType==2">
                                                        <a (click)="godetail(record)"
                                                            class="icon-1311shangpinfenleipicishuxing dropdown-item">{{l('detail')}}</a>
                                                    </li>
                                                    <li>
                                                        <a (click)="deleteSchedule(record)"
                                                            class="icon-icon-test dropdown-item">{{l('Delete')}}</a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </td>
                                        <!-- <td>
                                            <p-tableCheckbox [value]="record"></p-tableCheckbox>
                                        </td> -->
                                        <td> {{transIndex(i)}}</td>
                                        <td>
                                            <span>{{record.name}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.outerId}}</span>
                                        </td>
                                        <td>{{record.startTime | date : "yyyy/MM/dd HH:mm"}}</td>
                                        <td>{{record.endTime| date : "yyyy/MM/dd HH:mm"}}</td>
                                        <td>
                                            <span *ngIf="record.promotionType==0">{{l('InShop')}}</span>
                                            <span *ngIf="record.promotionType==1">{{l('InGroup')}}</span>
                                            <span *ngIf="record.promotionType==2">{{l('InProduct')}}</span>
                                        </td>
                                        <td>
                                            <span *ngIf="record.discountType==0">{{l('Voucher')}}</span>
                                            <span *ngIf="record.discountType==1">{{l('Discount')}}</span>
                                        </td>
                                        <td>
                                            <span>{{record.discountAmount}}</span>
                                        </td>
                                    </tr>
                                </ng-template>
                                <ng-template pTemplate="emptymessage" let-records>
                                    <tr *ngIf="primengTableHelper.records">
                                        <td colspan="9" class="text-center">
                                            <img class="emptymessage"
                                                src="/assets/common/images/placeholder/productHolder.png" />
                                        </td>
                                    </tr>
                                </ng-template>
                            </p-table>
                            <div class="primeng-paging-container">
                                <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage" #paginator
                                    (onPageChange)="getSchedule($event)"
                                    [totalRecords]="primengTableHelper.totalRecordsCount"
                                    [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">
                                </p-paginator>
                                <span class="total-records-count">
                                    {{l('TotalRecordsCount', primengTableHelper.totalRecordsCount)}}
                                </span>
                            </div>
                        </div>
                        <!--<Primeng-Datatable-End>-->
                    </div>

                </div>
            </div>
        </div>
        <promotionManageModal #promotionManageModal (modalSave)="getSchedule()"></promotionManageModal>
    </div>
</div>